# -*- coding: utf-8 -*-
__author__ = 'yangq'

from appcommon.appinstance import wechat_pool
from tornado import gen


@gen.coroutine
def get_vote_list():
    sql = (
        "select id as vote_id, vote_name, status, vote_type from vote_list "
        "order by id desc"
    )
    res = yield wechat_pool.get_all(sql, cursor='dict')
    raise gen.Return(res)


@gen.coroutine
def get_opt_list(vote_id):
    sql = (
        "select id as option_id, vote_id, opt_name, status from vote_options "
        "where vote_id = {}"
    )
    res = yield wechat_pool.get_all(sql.format(vote_id), cursor='dict')
    raise gen.Return(res)